<?php
declare(strict_types=1);

/**
 * This file is part of Swoft.
 *
 * @link     https://swoft.org
 * @document https://swoft.org/docs
 * @contact  group@swoft.org
 * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */
use Swoft\WebSocket\Server\WebSocketServer;
use Swoft\Db\Database;
use Swoft\Redis\RedisDb;
use Swoft\Server\SwooleEvent;
use Swoft\Task\Swoole\TaskListener;
use Swoft\Task\Swoole\FinishListener;
use Swoft\Http\Server\HttpServer;
use Swoft\Http\Server\Swoole\RequestListener;
use Swoft\Db\Pool;

return [
    'noticeHandler'      => [
        'logFile' => '@runtime/logs/notice-%d{Y-m-d-H}.log',
    ],
    'applicationHandler' => [
        'logFile' => '@runtime/logs/error-%d{Y-m-d}.log',
    ],
    'logger'            => [
    	'flushRequest' => true,
        'enable'       => true,
    	'json'         => true,
    ],
    'httpServer'        => [
        'class'    => HttpServer::class,
        'port'     => 18309,
        'process'  => [
//            'monitor' => bean(MonitorProcess::class)
//            'crontab' => bean(CrontabProcess::class)
        ],
        'on'       => [
//            SwooleEvent::TASK   => bean(SyncTaskListener::class),  // Enable sync task
            SwooleEvent::TASK   => bean(TaskListener::class),  // Enable task must task and finish event
            SwooleEvent::FINISH => bean(FinishListener::class)
        ],
        /* @see HttpServer::$setting */
        'setting' => [
            'task_worker_num'       => 1,
            'task_enable_coroutine' => true,
            'worker_num'            => 4
        ]
    ],
    'httpDispatcher'    => [
        // Add global http middleware
        'middlewares'      => [
            // \Swoft\Whoops\WhoopsMiddleware::class,
            \App\Http\Middleware\CorsMiddleware::class,
//             \Session\Middleware\SessionMeMiddleware::class
        ],
        'afterMiddlewares' => [
            \Swoft\Http\Server\Middleware\ValidatorMiddleware::class
        ]
    ],
    'db'                => [
        'class'    => Database::class,
        'dsn'      => 'mysql:dbname=chat;host=172.28.0.3',
        'username' => 'root',
        'password' => '123456',
        'charset' => 'utf8mb4',
    ],
    
    'db.pool' => [
        'class' => Pool::class,
        'database' => bean ( 'db' )
    ],
  
    'redis'             => [
        'class'    => RedisDb::class,
        'host'     => '172.28.0.4',
        'port'     => 6379,
        'database' => 0,
        'option'   => [
            'prefix' => 'swoft:'
        ]
    ],
    
    'redis.pool' => [
        'class' => \Swoft\Redis\Pool::class,
        'redisDb' => \bean('redis'),
        'minActive' => 10,
        'maxActive' => 20,
        'maxWait' => 0,
        'maxWaitTime' => 0,
        'maxIdleTime' => 60
    ],
    
    'wsServer'          => [
        'class'   => WebSocketServer::class,
        'port'    => 18308,
        'listener' => [
            // 'rpc' => bean('rpcServer'),
            // 'tcp' => bean('tcpServer'),
        ],
        'on'      => [
            // Enable http handle
            SwooleEvent::REQUEST => bean(RequestListener::class),
        ],
        'debug'   => 1,
        // 'debug'   => env('SWOFT_DEBUG', 0),
        /* @see WebSocketServer::$setting */
        'setting' => [
            'log_file' => alias('@runtime/swoole.log'),
        ],
    ],
    /** @see \Swoft\WebSocket\Server\WsMessageDispatcher */
    'wsMsgDispatcher' => [
        'middlewares' => [
        ],
    ],
   
    'cliRouter'         => [
        // 'disabledGroups' => ['demo', 'test'],
    ]
];
